package practice;

public class AnimalTest {
    public static void main(String[] args) {
        //第一遍
        Animal[] animals = new Animal[6];
        animals[0] = new Dog("大白",9,"白");
        animals[1] = new Dog("小白",8,"白");
        animals[2] = new Chick("大黑",7,"黑");
        animals[3] = new Chick("小黑",6,"黑");
        animals[4] = new Fish("大红",4,"红");
        animals[5] = new Fish("小红",3,"红");

        for(int i=0;i<animals.length;i++) {
            System.out.println(animals[i].name+"是"+animals[i].color+"色的，今年"+animals[i].age+"岁了！");
            animals[i].eat();
            animals[i].drink();

            if(animals[i] instanceof Dog) {
                Dog dogs = (Dog)animals[i];
                dogs.lookHome();
                dogs.swim();
            }

            if(animals[i] instanceof Chick) {
                Chick chicks = (Chick)animals[i];
                chicks.layEggs();
            }

            if(animals[i] instanceof Fish) {
                Fish fish = (Fish)animals[i];
                fish.swim();
            }
        }

        Dog dog = new Dog("小白",8,"白");
        Chick chick = new Chick("小绿",7,"绿");
        Fish fish = new Fish("小紫",6,"紫");
        Animal a = new Animal(){
            void eat() {
                System.out.println(11);
            }
        };
        a.feed(dog);
        new Animal(){
            void eat() {
                System.out.println(11);
            }
        }.feed(dog);

        new Animal(){
            void eat() {
                System.out.println(11);
            }
        }.feed(dog);





        //第二遍
//        Animal[] anis = new Animal[6];
//        anis[0] = new Dog("太白",10,"白");
//        anis[1] = new Dog("老白",11,"白");
//        anis[2] = new Chick("太红",12,"红");
//        anis[3] = new Chick("老红",13,"红");
//        anis[4] = new Fish("太黑",14,"黑");
//        anis[5] = new Fish("老黑",15,"黑");
//
//        for(int i=0;i<anis.length;i++) {
//            System.out.println(anis[i].name+"今年"+anis[i].age+"死了，死前始终是"+anis[i].color+"色的。");
//            anis[i].eat();
//            anis[i].drink();
//
//            if(anis[i] instanceof Dog) {
//                Dog dogs = (Dog)anis[i];
//                dogs.lookHome();
//                dogs.swim();
//            }
//
//            if(anis[i] instanceof Chick) {
//                Chick chicks = (Chick)anis[i];
//                chicks.layEggs();
//            }
//
//            if(anis[i] instanceof Fish) {
//                Fish fish = (Fish)anis[i];
//                fish.swim();
//            }
//        }
//        Dog dog = new Dog("老白",8,"白");
//        Chick chick = new Chick("老绿",7,"绿");
//        Fish fish = new Fish("老紫",6,"紫");
//        Master master = new Master();
//        master.feed(dog);
//        master.feed(chick);
//        master.feed(fish);
    }
}
